//
//  UnarmedDetailVC.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/12/30.
//

import Foundation
import UIKit

class UnarmedDetailVC: SubLevelViewController {
    let detailV = UnarmedDetailView()

    var label: String?
    var val: String?
    
    var model: AlarmCbfinfoModal?

    init(withDeptId deptId: Int64? = nil, deptName: String? = nil, label: String? = nil, val: String? = nil) {
        super.init(withDeptId: deptId, deptName: deptName)
        self.label = label
        self.val = val
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = deptName ?? "布防详情"
        view.backgroundColor = .bg
        
        setupUI()
        
        reloadData()
    }
    
    func reloadData() {
        view.showToastActivity()
//        API.getAlarmCbfinfo(withParam: AlarmWBFParam(date: date, deptId: "\(deptId ?? -1)", abfType: val)) { responseModel in
        API.getAlarmCbfinfo(withParam: AlarmWBFParam(date: date, deptId: "\(deptId ?? -1)")) { responseModel in
            DispatchQueue.main.async {
                self.detailV.updateUI(withModal: responseModel.model)
                self.view.hideToastActivity()
            }
        }
    }
    
    // MARK: - Setup
    
    func setupUI() {
        view.addSubview(detailV)
        detailV.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
        }
    }
    
}
